<template>
  <div class="app-container">
    <el-form :inline="true" :model="pageInfo" class="demo-form-inline">
      <el-form-item>
        <el-select v-model="pageInfo.sid" placeholder="省" @change="shch">
          <el-option
            v-for="item in slist"
            :key="item.regionId"
            :label="item.regionName"
            :value="item.regionId"
          />
        </el-select>
        <el-select v-model="pageInfo.cid" placeholder="市" @change="quch">
          <el-option
            v-for="item in citys"
            :key="item.regionId"
            :label="item.regionName"
            :value="item.regionId"
          />
        </el-select>
        <el-select v-model="pageInfo.did" placeholder="区" @change="quch">
          <el-option
            v-for="item in countrys"
            :key="item.regionId"
            :label="item.regionName"
            :value="item.regionId"
          />
        </el-select>
        <el-form-item>
          <el-input v-model="pageInfo.name" placeholder="请输入楼盘关键字" />
        </el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-form :inline="true" :model="pageInfo" class="demo-form-inline">
      <el-radio v-model="pageInfo.status" label="0">待看房</el-radio>
      <el-radio v-model="pageInfo.status" label="1">已看房</el-radio>
      <el-button type="primary" @click="update()">批量设置状态</el-button>
    </el-form>
    <template>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          prop="id"
          label="id"
          sortable
          width="180"
        />
        <el-table-column
          prop="name"
          label="楼盘名称"
          sortable
          width="180"
        />
        <el-table-column
          prop="showingsName"
          label="预约人"
          sortable
          width="180"
        />
        <el-table-column
          prop="showingsMobile"
          label="联系人电话"
          sortable
          width="180"
        />
        <el-table-column
          prop="roomName"
          label="预约房源"
          sortable
          width="180"
        />
        <el-table-column
          prop="reserveTime"
          label="预约时间"
          sortable
          width="180"
        />
        <el-table-column
          prop="status"
          label="预约状态"
          sortable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.status==0">待看房</span>
            <span v-if="scope.row.status==1">已看房</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      :current-page="pageInfo.pageNum"
      :page-sizes="[10, 30, 50, 70]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'Reservation',
  data() {
    return {
      tableData: [],
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
        sid: null,
        cid: null,
        did: null,
        name: null,
        status: null
      },
      slist: [],
      citys: [],
      countrys: [],
      ids: [],
      total: null,
      form: {
        id: '',
        name: '',
        showingsName: '',
        showingsMobile: '',
        roomName: '',
        reserveTime: '',
        status: ''
      }
    }
  },
  created() {
    this.list()
  },
  methods: {
    list() {
      axios.get('http://localhost:8200/hou/TbRoomReservationController/selects', { params: this.pageInfo }).then((response) => {
        console.log(response.data)
        this.tableData = response.data.obj.list
        this.pageInfo.pageNum = response.data.obj.pageNum
        this.pageInfo.pageSize = response.data.obj.pageSize
        this.total = response.data.obj.total
      })
      axios.get('http://localhost:8200/sys/region/getArea?pid=' + 1).then((response) => {
        this.slist = response.data.obj
      })
    },

    handleSelectionChange(val) {
      // eslint-disable-next-line no-array-constructor
      this.ids = new Array()
      for (const i of val) {
        this.ids.push(i.id)
      }
    },
    update() {
      if (this.ids.length < 1) {
        alert('请至少选择一条数据')
      } else if (this.pageInfo.status == null) {
        alert('请选择状态')
      }
      axios.post('http://localhost:8200/hou/TbRoomReservationController/update?status=' + this.pageInfo.status + '&ids=' + this.ids).then((response) => {
        if (response.data) {
          alert('成功')
          this.list()
        } else {
          alert('失败')
        }
      })
    },
    shch() {
      this.citys = []
      axios.get('http://localhost:8200/sys/region/getArea?pid=' + this.pageInfo.sid).then((response) => {
        this.citys = response.data.obj
      })
    },
    quch() {
      this.countrys = []
      axios.get('http://localhost:8200/sys/region/getArea?pid=' + this.pageInfo.cid).then((response) => {
        this.countrys = response.data.obj
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageInfo.pageSize = val
      this.list()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageInfo.pageNum = val
      this.list()
    },
    onSubmit() {
      console.log('submit!')
      this.list()
    }
  }
}
</script>

<style scoped>

</style>
